package com.terabits.smartriver.mapper;

import com.terabits.smartriver.meta.po.Alarm;
import com.terabits.smartriver.util.PageData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface AlarmMapper extends Mapper<Alarm> {
    /**
     * 查询告警
     *
     * @param param
     * @return
     */
    List<PageData> selectAlarm(@Param("pd") PageData param);

    /**
     * 得到水质监测数据
     *
     * @param param
     * @return
     */
    List<PageData> selectWaterQuality(@Param("pd") PageData param);

    /**
     * 水质取样数据
     *
     * @param param
     * @return
     */
    List<PageData> selectWaterSampling(@Param("pd") PageData param);

    /**
     * 地图监控-企业
     *
     * @return
     */
    List<PageData> selectMapEnterprise(@Param("pd")PageData pageData);

    /**
     * 地图监控-项目
     *
     * @return
     */
    List<PageData> selectMapProjectDevices(@Param("pd")PageData pageData);

    /**
     * 项目水质异常次数
     *
     * @param projectNum
     * @return
     */
    @Select("SELECT COUNT(*) FROM alarm WHERE device_num IN(SELECT device_num FROM device WHERE project_num=#{projectNum}) AND model_id=1")
    Integer selectCountByProjectWater(@Param("projectNum") String projectNum);

    /**
     * 项目异常次数除了水质
     *
     * @param projectNum
     * @return
     */
    @Select("SELECT COUNT(*) FROM alarm WHERE device_num IN(SELECT device_num FROM device WHERE project_num=11) AND model_id NOT IN (1)")
    Integer selectCountByProjectOther(@Param("projectNum") String projectNum);
}